<template>
    <div class="register-form">
        <div class="form-input">
            <van-field v-model="password" :type="!type ? 'password' : 'text'" placeholder="请设置6-20位登录密码"
                 @click-right-icon="type = !type" clearable :right-icon="type ? 'eye-o' : 'closed-eye'" />
        </div>
        <div class="form-btn">
            <van-button @click="finish" :disabled="!flag" color="linear-gradient(to right, #ee0a24, #ff6034)" block
                round>完成</van-button>
        </div>
        </div>
</template>

<script>
import { doRegister } from '@/apis/user/index';

    export default {
          data() {
        return {
            type: true,
            password: '1222',
            tel: ''
        }
    },
    created() {
        this.tel = localStorage.getItem("tel")
        console.log(this.tel)
    },
    methods: {
        finish() {
            doRegister({
                loginname: this.tel,
                password:this.password
            }).then(res=>{
                if(res.data.code!=200) {
                    console.log(res)
                    showToast(res.data.message);return}
                this.$router.push('/login')
            })
        }
    },
    computed: {
        flag() {
            return /^\d{6}$/.test(this.password)
    }
    }
}
</script>

<style scoped>

</style>